package com.renzhebiao.lkang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.renzhebiao.lkang.comment.Need;
import com.renzhebiao.lkang.entity.ContactPO;
import com.renzhebiao.lkang.facade.ContactFacade;
import com.renzhebiao.lkang.master.ExecuteResult;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.ContactQuery;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 联系表 前端控制器
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@RestController
@RequestMapping("/contact")
@Api(tags = "联系记录")
public class ContactController {

    @Autowired
    private ContactFacade contactFacade;

    @ApiOperation(value = "新增联系记录", notes = "新增联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/add")
    @Need(token = true)
    public ExecuteResult<?> add(@RequestBody ContactPO po) {
        this.contactFacade.add(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "修改联系记录", notes = "修改联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/edit")
    @Need(token = true)
    public ExecuteResult<?> edit(@RequestBody ContactPO po) {
        this.contactFacade.edit(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "删除联系记录", notes = "删除联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/delete")
    @Need(token = true)
    public ExecuteResult<?> delete(@RequestBody Long id) {
        this.contactFacade.delete(id);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "查询联系记录列表", notes = "查询联系记录列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/list")
    public ExecuteResult<?> getContactList(@RequestBody ContactQuery param) {
        return ExecuteResult.ok(this.contactFacade.getContactList(param));
    }

    @ApiOperation(value = "查询联系记录单条", notes = "查询联系记录单条", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/get")
    public ExecuteResult<?> getContact(@RequestBody Long id) {
        return ExecuteResult.ok(this.contactFacade.getContact(id));
    }

    @ApiOperation(value = "分页查询联系记录", notes = "分页查询联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/page")
    public ExecuteResult<?> getContactByPage(@RequestBody PaginationDTO<ContactQuery, Void> paging) {
        return ExecuteResult.ok(this.contactFacade.getContactByPage(paging));
    }

}
